package com.sjz.service;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import com.sjz.utls.StreamTool;

public class ImageService {
	/**
	 * 获取网络图片的数据
	 * @param path 网络图片路径
	 * @return
	 */
	public static byte[] getImage(String path) throws Exception{
		URL url = new URL(path);
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();//基于HTTP协议连接对象
		conn.setConnectTimeout(5000);
		conn.setRequestMethod("GET");
		if(conn.getResponseCode() == 200){  //如果状态成功的话，读取流的数据，转换成字节数组
			InputStream inStream = conn.getInputStream();
			return StreamTool.read(inStream);
		}
		return null;
	}
}
